﻿using System;
using System.Collections.Generic;
using System.Configuration;

namespace FunctionalCLR.Core {
    public class DefaultDependencyManager {

        private static DefaultDependencyManager dm = new DefaultDependencyManager();

        private IConstantManager constantManager = null;

        private IFunctionManager functionManager = null;

        private IExpressionCompiler expressionCompiler = null;

        private IParserFactory parserFactory = null;

        private Dictionary<string, object> functions = null;

        private DefaultFunctionLoader dfl = null;

        protected DefaultDependencyManager() {
        }

        public static DefaultDependencyManager Instance {
            get {
                return dm;
            }
        }

        public IParserFactory ParserFactory {
            get {
                if (parserFactory == null) {
                    parserFactory = new DefaultParserFactory();
                }

                return parserFactory;
            }
            set {
                this.parserFactory = value;
            }
        }

        public IConstantManager ConstantManager {
            get {
                if (this.constantManager == null) {
                    string fileName = Utils.ConstantFile;
                    this.constantManager = new DefaultConstantManager(fileName);
                }

                return this.constantManager;
            }
            set {
                this.constantManager = value;
            }
        }

        public IFunctionManager FunctionManager {
            get {
                if (this.functionManager == null) {
                    this.functionManager = new DefaultFunctionManager();
                }

                return this.functionManager;
            }
            set {
                this.functionManager = value;
            }
        }

        public IExpressionCompiler ExpressionCompiler {
            get {
                if (this.expressionCompiler == null) {
                    this.expressionCompiler = new DefaultExpressionCompiler();
                }

                return this.expressionCompiler;
            }
            set {
                this.expressionCompiler = value;
            }
        }
    }
}
